#!/bin/sh

basedir="/Users/hbaolong/workshop/gitee/3place/ /Users/hbaolong/workshop/gitee/yumo/"

returnvalue=0

counter=0

#for dirs in `find $basedir |grep  -w config$  |sort |awk -F "config" '{print $1}'|sed -e "/\./d"|sed -e "/\/\/$/d"`
for dirs in `find $basedir |grep  -w config$  |sort |awk -F "config" '{print $1}'|sed -e "/\./d"`
do
	name=`echo $dirs | awk -F \/ '{print $(NF-1)}'`
	echo "UPDATING " $name 
	cd $dirs
	upm config 

	r=$?

	if [ $r -ne 0 ]; then

		if [ -e upme ]; then
			./upme
		fi
	fi

	((returnvalue=returnvalue+$r))

	((counter=counter+1))

done

rm -f tmp.md

echo $counter " books running today."

if [ $returnvalue -ne 0 ]; then
	# 生成根目录

	gen3index

	# 生成根阅读日历

	#date
	#readcal

	# 生成根今日速览

	#date
	#readtoday
	# 生成同读书单
	genbooklist

	genallhash

	echo "something （$returnvalue) change UPDATING the github"
	/usr/local/bin/ups
fi
